package smarttoursclient;

import java.util.ArrayList;
import lab5.grp02FlightReservation;

/**
 *
 * @author grp02 - Pascal Charreix and Meike Paetz
 *
 * This is the Smart Tours client
 */
public class SmartToursClient {

    private grp02FlightReservation port;

    /**
     *
     * This is the main which computes/starts all tasks required in the lab memo
     */
    public static void main(String[] args) {
        SmartToursClient client = new SmartToursClient();
        ArrayList<Integer> opened;
        client.createReservation();
        opened = client.getOpen();
        client.submitReservation(opened.get(0));
        client.getInformation(opened.get(0));
        client.deleteReservation(opened.get(0));
    }

    /**
     *
     * This is the standard constructor
     */
    public SmartToursClient() {
        port = new grp02FlightReservation();
    }

    /**
     *
     * This is to create 4 different reservations
     */
    public void createReservation() {
        System.out.println("CreateReservation");
        int tmp;
        tmp = port.createFlightReservation("Paris", "Stuttgart",
                1318241080, 12, 1, 0, "Air France");
        getInformation(tmp);
        tmp = port.createFlightReservation("Toulouse", "Berlin",
                1318241080, 12, 1, 1, "KLM");
        getInformation(tmp);
        tmp = port.createFlightReservation("Lyon", "Frankfurt",
                1318241080, 12, 1, 0, "Lufthansa");
        getInformation(tmp);
        tmp = port.createFlightReservation("Marseille", "Hamburg",
                1318241080, 12, 2, 1, "Air Corsica");
        getInformation(tmp);
    }

    /**
     *
     * This is to get a confimation
     */
    public ArrayList<Integer> getConfirmed() {
        System.out.println("GetConfirmed");
        ArrayList<Integer> tab = port.getConfirmedList();
        int i = 0;
        int len = tab.size();
        while (i < len) {
            getInformation(tab.get(i));
            i++;
        }
        return tab;
    }

    /**
     *
     * This is to get open reservations
     */
    public ArrayList<Integer> getOpen() {
        System.out.println("GetOpen");
        ArrayList<Integer> tab = port.getOpenList();
        int i = 0;
        int len = tab.size();
        while (i < len) {
            getInformation(tab.get(i));
            i++;
        }
        return tab;
    }

    /**
     *
     * This is to submit reservation
     */
    public void submitReservation(int id) {
        System.out.println("SubmitReservation");
        if (port.confirmReservation(id) > 0) {
            System.out.println(id + " has been successfully reserved.");
        } else {
            System.out.println(id + " reservation failed.");
        }
        getInformation(id);
    }

    /**
     *
     * This is to get information about the reservations
     */
    public void getInformation(int id) {
        System.out.println("GetInformation");
        System.out.println(port.getReservationInformation(id));
    }

    /**
     *
     * This is to delete a reservation
     */
    public void deleteReservation(int id) {
        System.out.println("DeleteReservation");
        if (port.cancelReservation(id) == -1) {
            System.out.println("Can't delete Reservation " + id + ".");
        }
    }
}